﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.Catering_Page.richang
{
    public partial class DailyMoonwf : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        [System.Web.Services.WebMethod]
        public static System.Collections.ArrayList GetMoonForDropDownList(string _classid)
        {
            Catering_Rules.Moon _moonrules = new Catering_Rules.Moon();
            var listmoon = _moonrules.GetModelList(" ClassId = " + _classid);
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            foreach (var item in listmoon)
            {
                al.Add(item.Id + "," + item.MoonName);
            }
            return al;
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static System.Collections.ArrayList Get(string dialyid, string moonId)
        {
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            try
            {
                Catering_Model.DailyMoon _model = new Catering_Model.DailyMoon();
                Catering_Rules.DailyMoon dailymoon = new Catering_Rules.DailyMoon();
                string where = " DailyID = '" + dialyid + "'";
                if (!string.IsNullOrEmpty(moonId) && !moonId.Equals("0") && !moonId.Equals("-1"))
                {
                    where += " and MoonID = " + moonId;
                }

                var listdailymoon = dailymoon.GetModelList(where);
                if (listdailymoon != null && listdailymoon.Count > 0)
                {
                    _model = listdailymoon.First();
                }
                else
                {
                    if (!string.IsNullOrEmpty(moonId) && !moonId.Equals("0") && !moonId.Equals("-1"))
                    {
                        _model = dailymoon.GetLastDailyMoon(1, "MoonID = " + moonId, " id desc ");
                        _model.id = 0;
                    }
                }


                al.Add(_model.WoJu != null ? _model.WoJu.ToString() : "");
                al.Add(_model.CanJu != null ? _model.CanJu.ToString() : "");
                al.Add(_model.Rice != null ? _model.Rice.ToString() : "");
                al.Add(_model.Surfice != null ? _model.Surfice.ToString() : "");
                al.Add(_model.Oil != null ? _model.Oil.ToString() : "");
                al.Add(_model.DishDate != null ? _model.DishDate.Value.ToShortDateString() : "");
                al.Add(_model.CheckDate != null ? _model.CheckDate.Value.ToShortDateString() : "");
                al.Add(_model.Area != null ? _model.Area.ToString() : "");
                al.Add(_model.Oilstove != null ? _model.Oilstove.ToString() : "");
                al.Add(_model.SmokeMachineWash != null ? _model.SmokeMachineWash.ToString() : "");
                al.Add(_model.FireExtinguisher != null ? _model.FireExtinguisher.ToString() : "");
                al.Add(_model.FireBlanket != null ? _model.FireBlanket.ToString() : "");
                al.Add(_model.HighRiskEqui != null ? _model.HighRiskEqui.ToString() : "");
                al.Add(_model.DailyID);
                al.Add(_model.inWorkNum != null ? _model.inWorkNum.ToString() : "");
                al.Add(_model.unWorkNum != null ? _model.unWorkNum.ToString() : "");
                al.Add(_model.id);
                al.Add(_model.IsCommunicate ? "true" : "false");
                al.Add(_model.EquiOperation);
                al.Add(_model.bedsnum != null ? _model.bedsnum.ToString() : "");
                al.Add(_model.MoonID);
            }
            catch
            {
                al.Add("error");
            }
            return al;
        }

        /// <summary>
        /// 新增
        /// 编写：章建国
        /// </summary>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string Add(string _WoJu, string _CanJu, string _Rice, string _Surfice, string _Oil, string _DishDate,
            string _CheckDate, string _IsCommunicate, string _Area, string _Oilstove, string _SmokeMachineWash,
            string _FireExtinguisher, string _FireBlanket, string _HighRiskEqui, string inWorkNum, string unWorkNum, string dailyid,
            string _id, string EquiOperation, string ddl_moon, string bedsnum)
        {
            string mes = "error";
            Catering_Model.DailyMoon _model = new Catering_Model.DailyMoon();
            Catering_Rules.DailyMoon dailymoon = new Catering_Rules.DailyMoon();

            if (!string.IsNullOrEmpty(_id))
            {
                int id = Convert.ToInt32(_id);
                if (id > 0)
                {
                    _model = dailymoon.GetModel(id);
                }
            }

            #region 参数赋值
            try
            {
                _model.IsCommunicate = _IsCommunicate == "是" ? true : false;
                _model.DailyID = dailyid;
                _model.EquiOperation = EquiOperation;
                _model.AddDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                if (!string.IsNullOrEmpty(_DishDate))
                {
                    try
                    {
                        _model.DishDate = Convert.ToDateTime(_DishDate);
                    }
                    catch
                    {
                    }
                }
                if (!string.IsNullOrEmpty(_CheckDate))
                {
                    try
                    {
                        _model.CheckDate = Convert.ToDateTime(_CheckDate);
                    }
                    catch
                    {
                    }
                }
                if (!string.IsNullOrEmpty(_Area))
                {
                    _model.Area = Convert.ToDecimal(_Area);
                }
                if (!string.IsNullOrEmpty(_Oilstove))
                {
                    _model.Oilstove = Convert.ToDecimal(_Oilstove);
                }
                if (!string.IsNullOrEmpty(_SmokeMachineWash))
                {
                    _model.SmokeMachineWash = Convert.ToInt32(_SmokeMachineWash);
                }
                if (!string.IsNullOrEmpty(_FireExtinguisher))
                {
                    _model.FireExtinguisher = Convert.ToInt32(_FireExtinguisher);
                }
                if (!string.IsNullOrEmpty(ddl_moon))
                {
                    _model.MoonID = Convert.ToInt32(ddl_moon);
                }
                if (!string.IsNullOrEmpty(unWorkNum))
                {
                    _model.unWorkNum = Convert.ToInt32(unWorkNum);
                } if (!string.IsNullOrEmpty(inWorkNum))
                {
                    _model.inWorkNum = Convert.ToInt32(inWorkNum);
                }
                if (!string.IsNullOrEmpty(_HighRiskEqui))
                {
                    _model.HighRiskEqui = Convert.ToInt32(_HighRiskEqui);
                }
                if (!string.IsNullOrEmpty(_FireBlanket))
                {
                    _model.FireBlanket = Convert.ToInt32(_FireBlanket);
                }
                if (!string.IsNullOrEmpty(_Oil))
                {
                    _model.Oil = Convert.ToDecimal(_Oil);

                }
                if (!string.IsNullOrEmpty(_Surfice))
                {
                    _model.Surfice = Convert.ToDecimal(_Surfice);
                }
                if (!string.IsNullOrEmpty(_Rice))
                {
                    _model.Rice = Convert.ToDecimal(_Rice);
                }
                if (!string.IsNullOrEmpty(_CanJu))
                {
                    _model.CanJu = Convert.ToInt32(_CanJu);
                }
                if (!string.IsNullOrEmpty(_WoJu))
                {
                    _model.WoJu = Convert.ToInt32(_WoJu);
                }
                if (!string.IsNullOrEmpty(bedsnum))
                {
                    _model.bedsnum = Convert.ToInt32(bedsnum);
                }
            }
            catch
            {
                return mes;
            }
            //_model.ClassID = Convert.ToInt32(Session["ClassID"].ToString());
            #endregion 参数赋值

            if (_model.id > 0)
            {
                if (dailymoon.Update(_model))
                {
                    mes = "ok";
                }
            }
            else
            {
                if (dailymoon.Add(_model) > 0)
                {
                    mes = "ok";
                }
            }

            return mes;
        }

        /// <summary>
        /// 删除
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string Del(string _id)
        {
            string mes = "error";
            if (!string.IsNullOrEmpty(_id))
            {
                Catering_Rules.DailyMoon dailymoon = new Catering_Rules.DailyMoon();
                int id = Convert.ToInt32(_id);
                if (dailymoon.Delete(id))
                {
                    mes = "ok";
                }
            }
            return mes;
        }
    }
}